def dfs(visited,i,pre):
    if visited[i]==1:
        return False
    if visited[i]==-1:
         return True 
    visited[i]=1
    for p in pre[i]:
        if not dfs(visited,p,pre): return False 
    visited[i]=-1
    return True


def solve(numCourses,prerequisites):
    pre=[[] for _ in range(numCourses)]
    for i in prerequisites:
        pre[i[0]].append(i[1])
    visited=[0]*numCourses
    for i in range(numCourses):
        if not dfs(visited,i,pre): return False 
    return True


numCourses = 2
prerequisites = [[1,0]]
print(solve(numCourses,prerequisites))
    